<script type="text/javascript" src="../js/jscharts.js"></script>
<?php 	

function setFilePath()
{	
	return "../Clients/".$_SESSION['ClientID']."/drivespace.log";
}
if(isset($_SESSION["clientdownload"]) && $_SESSION["clientdownload"] != "")
{

	echo "<div class='header1'>". $_SESSION["clientname"]."</div>";
	echo "<br /><br />";
	echo "<div class='feedbackCorrect' style='text-align:center'>Please Query with Caution. Large amount of data Could slow down the Browser!</div>";
	echo "<div id='graph'></div>";
?>
<script type="text/javascript">
if (window.XMLHttpRequest)
  {	
  	// code for IE7+, Firefox, Chrome, Opera, Safari
 	 xmlhttp=new XMLHttpRequest();
  }
else
  {	
  	// code for IE6, IE5
  	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }

  
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {    	
	alert(xmlhttp.responseText);
    var response=xmlhttp.responseText;
      
  	// convert received string to JavaScript object
    	var JSONobject = JSON.parse(response);
	stYear 	=   Number(JSONobject['firstdate'].substr(0,4));
	stMonth =   Number(JSONobject['firstdate'].substr(5,2));
	stDay 	=   Number(JSONobject['firstdate'].substr(8,2));
	enYear 	=   Number(JSONobject['lastdate'].substr(0,4));
	enMonth =   Number(JSONobject['lastdate'].substr(5,2));
	enDay 	=   Number(JSONobject['lastdate'].substr(8,2)); 
	
	document.getElementById("BodyMain").innerHTML ="Start Date<br />";
	var tempStr = "<select id='startYear' name='startYear'  >";
	
	for(i = stYear; i <= enYear ; i++)
	{
		tempStr += "<option value=\""+i+"\">"+i+"</option>";		
	}
	tempStr += "	</select>";
	document.getElementById("BodyMain").innerHTML += tempStr;
	document.getElementById("BodyMain").innerHTML += "<select id='startMonth' name='month' ><option value='01'>January</option><option value='02'>February</option><option value='03'>March</option><option value='04'>April</option><option value='05'>May</option><option value='06'>June</option><option value='07'>July</option><option value='08'>August</option><option value='09'>September</option><option value='10'>October</option><option value='11'>November</option><option value='12'>December</option></select>";
	document.getElementById("BodyMain").innerHTML += "<select id='startDay' name=day >      <option value='01'>01</option><option value='02'>02</option><option value='03'>03</option><option value='04'>04</option><option value='05'>05</option>		<option value='06'>06</option><option value='07'>07</option><option value='08'>08</option><option value='09'>09</option><option value='10'>10</option><option value='11'>11</option><option value='12'>12</option><option value='13'>13</option><option value='14'>14</option><option value='15'>15</option><option value='16'>16</option><option value='17'>17</option><option value='18'>18</option><option value='19'>19</option><option value='20'>20</option><option value='21'>21</option><option value='22'>22</option><option value='23'>23</option><option value='24'>24</option><option value='25'>25</option><option value='26'>26</option><option value='27'>27</option><option value='28'>28</option><option value='29'>29</option><option value='30'>30</option><option value='31'>31</option></select>";
	
	
	
	
	document.getElementById("BodyMain").innerHTML +="<br />End Date<br />";
		var tempStr = "<select id='endYear' name='startYear'  >";
		
		for(i = stYear; i <= enYear ; i++)
		{
			tempStr += "<option value=\""+i+"\">"+i+"</option>";		
		}
		tempStr += "	</select>";
		document.getElementById("BodyMain").innerHTML += tempStr;
		document.getElementById("BodyMain").innerHTML += "<select id='endMonth' name='endMonth' value='' ><option value='01'>January</option><option value='02'>February</option><option value='03'>March</option><option value='04'>April</option><option value='05'>May</option><option value='06'>June</option><option value='07'>July</option><option value='08'>August</option><option value='09'>September</option><option value='10'>October</option><option value='11'>November</option><option value='12'>December</option></select>";
		document.getElementById("BodyMain").innerHTML += "<select id='endDay'   name='endDay' value=''>   <option value='01'>01</option><option value='02'>02</option><option value='03'>03</option><option value='04'>04</option><option value='05'>05</option>		<option value='06'>06</option><option value='07'>07</option><option value='08'>08</option><option value='09'>09</option><option value='10'>10</option><option value='11'>11</option><option value='12'>12</option><option value='13'>13</option><option value='14'>14</option><option value='15'>15</option><option value='16'>16</option><option value='17'>17</option><option value='18'>18</option><option value='19'>19</option><option value='20'>20</option><option value='21'>21</option><option value='22'>22</option><option value='23'>23</option><option value='24'>24</option><option value='25'>25</option><option value='26'>26</option><option value='27'>27</option><option value='28'>28</option><option value='29'>29</option><option value='30'>30</option><option value='31'>31</option></select>";
		document.getElementById("BodyMain").innerHTML +="	<br /><br />";
		document.getElementById("BodyMain").innerHTML +="	<input type='checkbox' id='Min' name='Min' value='Minimum' > Minimum<br>";
		document.getElementById("BodyMain").innerHTML +="	<input type='checkbox' id='Max' name='Max' value='Maximum' > Maximum<br>"
		document.getElementById("BodyMain").innerHTML +="	<input type='checkbox' id='Mean' name='Mean' value='Mean'> Mean<br>";
		document.getElementById("BodyMain").innerHTML +="	<input type='checkbox' id='firstdate' name='firstdate' value='First Date' > firstdate<br>";
		document.getElementById("BodyMain").innerHTML +="	<input type='button'   id='submit' name='Submit' value='Submit' onClick='buildString();' / >";
		document.getElementById("BodyMain").innerHTML +="	<input type='reset'    id='Reset' name='Reset' value='Reset' / >";
		document.getElementById("BodyMain").innerHTML +="	<br />";
		
		tempStr  = "<div> Last Date For Drive Access:";
		tempStr += JSONobject['lastdate'];
		tempStr += "</div>";
		tempStr += "<div>Last Drive Space Size:";
		tempStr += JSONobject[JSONobject['lastdate']];
		tempStr += "</div>";
		tempStr += "<div>Quota Size:";
		tempStr += JSONobject['quota'];
		tempStr += "</div>";
		
		if(Number(JSONobject[JSONobject['lastdate']]) > Number(JSONobject['quota']) )
			tempStr += "<div style='bgcolor:red'>You have surpassed your quota!</div>";

		document.getElementById("BodyMain").innerHTML += tempStr;	
		document.getElementById("BodyMain").innerHTML +="";

		//setting the default values	
		document.getElementById("startMonth").selectedIndex = stMonth - 1;
		document.getElementById("startDay").selectedIndex = stDay - 1;
		document.getElementById("endDay").selectedIndex = enDay - 1;	
		document.getElementById("endMonth").selectedIndex = enMonth - 1;
		document.getElementById("endYear").selectedIndex = enYear - stYear ;	   	
	   	
    }
  }
xmlhttp.open("GET","./../phplib/GetDriveSpace.php?firstdate=1&lastdate=1&quota=1",true);
xmlhttp.send();

</script>
<div id="BodyMain" ></div>
<div id="content" style="position:relative; left:200px"></div>
<?php 
}
elseif(isset($_SESSION["clientdownload"]) && $_SESSION["clientdownload"] == "")
{
	echo "<h2 class=\"header1\">system has not been configured for them to download files.</h2>";
}
else
{
	echo "<h2 class=\"header1\">Configuration Error.</h2>";
}
?>
<script type="text/javascript">
var strToPassGetDriveSPace;

function buildString()
{
	
	strToPassGetDriveSPace = "./../phplib/GetDriveSpace.php?startdate="+document.getElementById("startYear").value+"-"+document.getElementById("startMonth").value+"-"+document.getElementById("startDay").value+"&enddate="+document.getElementById("endYear").value+"-"+document.getElementById("endMonth").value+"-"+document.getElementById("endDay").value+"&drivespacedata=1";
	if(document.getElementById("Min").checked)
		strToPassGetDriveSPace = strToPassGetDriveSPace + "&min=1";
	if(document.getElementById("Max").checked)
		strToPassGetDriveSPace = strToPassGetDriveSPace + "&max=1";
	if(document.getElementById("Mean").checked)
		strToPassGetDriveSPace = strToPassGetDriveSPace + "&mean=1";
	if(document.getElementById("firstdate").checked)
		strToPassGetDriveSPace = strToPassGetDriveSPace + "&firstdate=1";

	
	getData(strToPassGetDriveSPace);
}
var JSONobject;

function getData(str)
{

if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    
  	
    var response=xmlhttp.responseText;
  	// convert received string to JavaScript object
    JSONobject = JSON.parse(response);

	 document.getElementById("content").innerHTML = "";
	 if(JSONobject["max"])
		 document.getElementById("content").innerHTML = document.getElementById("content").innerHTML + "Maximum = " + JSONobject["max"] + "<br />";
	 if(JSONobject["min"])
		 document.getElementById("content").innerHTML = document.getElementById("content").innerHTML + "Minimum = " + JSONobject["min"] + "<br />";
	 if(JSONobject["mean"])
		 document.getElementById("content").innerHTML = document.getElementById("content").innerHTML + "Mean = " + JSONobject["mean"] + "<br />";		 
	 if(JSONobject["firstdate"])
		 document.getElementById("content").innerHTML =  document.getElementById("content").innerHTML +"First Date = " + JSONobject["firstdate"] + "<br />";	
	 if(JSONobject["lastdate"])
		 document.getElementById("content").innerHTML =  document.getElementById("content").innerHTML +"Last Date = " + JSONobject["lastdate"] + "<br />";	


	  document.getElementById("content").innerHTML = document.getElementById("content").innerHTML +"<br /><br /><br />====================<br /> Date = Size (M) <br />====================<br />";
    for (var key in JSONobject) {
    	if(key != "min" && key != "max" && key != "mean" && key != "firstdate" && key != "lastdate")
      		document.getElementById("content").innerHTML = document.getElementById("content").innerHTML + key + " = " +JSONobject[key]+"<br />";
    }    
    }
  }
xmlhttp.open("GET",str,true);
xmlhttp.send();
}

</script>

